package dao;

import java.util.List;



import model.New;

import org.hibernate.Query;

public class NewDao extends BaseDao<New> {
	
	public void delete(Integer id){
		String hql = "DELETE FROM New n WHERE n.id = ?";
		getSession().createQuery(hql).setInteger(0, id).executeUpdate();
	}
	
	public List<New> getAll(){
		String hql = "FROM New";		
		return getSession().createQuery(hql).list();
	}
	
	public List<New> getTest(){
		String hql = "FROM New n WHERE n.isTest = ? ";
		Query query = getSession().createQuery(hql);
		query.setInteger(0, 0);
		return query.list();
	}
	
	public List<New> getTest1(){
		String hql = "FROM New n WHERE n.isTest = ? ";
		Query query = getSession().createQuery(hql);
		query.setInteger(0, 1);
		return query.list();
	}
	
	public void saveOrUpdate(New news){
		getSession().saveOrUpdate(news);
	}
	
	
	public New get(Integer id){
		return (New) getSession().get(New.class, id);
	}
	
	public List<New> getT1(){
		String hql = "FROM New n WHERE n.test = ? ";
		Query query = getSession().createQuery(hql);
		String s = "sh";
		query.setString(0, s);
		return query.list();
	}
	
	public List<New> getT2(){
		String hql = "FROM New n WHERE n.test = ? ";
		Query query = getSession().createQuery(hql);
		String s = "yl";
		query.setString(0, s);
		return query.list();
	}
	
	public List<New> getT3(){
		String hql = "FROM New n WHERE n.test = ? ";
		Query query = getSession().createQuery(hql);
		String s = "js";
		query.setString(0, s);
		return query.list();
	}
	
	public List<New> getT4(){
		String hql = "FROM New n WHERE n.test = ? ";
		Query query = getSession().createQuery(hql);
		String s = "ty";
		query.setString(0, s);
		return query.list();
	}
	
	public List<New> getById(Integer id){
		String hql = "FROM New n WHERE n.id = ? ";
		Query query = getSession().createQuery(hql);
		query.setInteger(0, id);
		return query.list();
	}
	
	public List<New> getById(String s){
		String hql = "FROM New n WHERE n.test = ? ";
		Query query = getSession().createQuery(hql);
		query.setString(0, s);
		return query.list();
	}
	
}
